package main

import (
	"context"
	"fmt"
	"time"

	clientv3 "go.etcd.io/etcd/client/v3"
)

type CmdbConfig struct {
	Http string `json:"http"`
}

func main() {
	client, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"127.0.0.1:2379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		panic(err)
	}

	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
	resp, err := client.MemberList(ctx)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)

	objectKey := "/registry/configs/default/cmdb"

	ch := client.Watch(context.Background(), objectKey)
	for v := range ch {
		for i := range v.Events {
			e := v.Events[i]
			fmt.Println(string(e.Kv.Key), string(e.Kv.Value))
		}
	}
}
